package com.lz;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @description
 *
 * @date 2021-11-08 11:18
 *
 * @author Lizhong
 */
public class Xx {
    static ExecutorService executorService = Executors.newFixedThreadPool(2);

    public static void main(String[] args) {

        // if (rs >= SHUTDOWN &&
        //         ! (rs == SHUTDOWN && firstTask == null && ! workQueue.isEmpty()))
        //     return false;
        /* true 不会创建Worker
         * rs >= SHUTDOWN && ( rs !=shutdown || first !=null || queueIsEmpty())
         * 1. rs > shutdown
         * 2. rs >= SHUTDOWN && first !=null
         * 3. rs >= SHUTDOWN && queueIsEmpty()
         */
        Runnable command = new MyRunner();
        // for (int i = 0; i < 4; i++) {
        //     executorService.execute(command);
        // }
        // executorService.shutdownNow();
        // executorService.submit(Xx::block);
        for (int i = 0; i < 10; i++) {
            executorService.execute(Xx::exception);
        }


        executorService.shutdown();

    }

    public static void block() {

        try {
            Thread.sleep(50000);
        } catch (InterruptedException e) {
            System.out.println("我被中断了");
        }
    }

    public static void compute() {
        int i = 0;
        for (; ; ) {
            if (Thread.currentThread().isInterrupted()) {
                break;
            }
            System.out.println(i++);
        }

    }

    public static void exception() {
        System.out.println(Thread.currentThread().getId());
        throw new RuntimeException();
    }
}
